package com.twu.biblioteca.commandexecutor.subexecutors;

import com.twu.biblioteca.commandexecutor.BibliotecaCommandExecutor_SubModules;
import com.twu.biblioteca.commandexecutor.ProgramExitRequestedException;
import com.twu.biblioteca.librarycollection.LibraryCollection;
import com.twu.biblioteca.memberdata.MemberData;
import com.twu.biblioteca.memberdata.UserDetails;

public class ListBooksSubExecutor implements BibliotecaCommandExecutor_SubModules.SubExecutor
    {
        int menuPos = -1;

        public ListBooksSubExecutor(int menuPos)
        {
            this.menuPos = menuPos;
        }

        public String getMenuOptionText()
        {
            return menuPos + "";
        }

        public String getMenuOptionDescription()
        {
            return "List books";
        }

        public boolean canExecute(String command)
        {
            if(command.equals(getMenuOptionText()))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public String execute(LibraryCollection libraryColl, MemberData memberData, UserDetails userDetails, String command) throws ProgramExitRequestedException
        {
            StringBuffer buf = new StringBuffer();
            for(String book : libraryColl.getBooks())
            {
                buf.append(book);
                buf.append("\n");
            }
            return buf.toString();
        }

        @Override
        public boolean isDone() {
            return true;
        }

        @Override
        public void reset() {
            //Do nothing; we have no state
        }
    }
